package cn.sciento.dd.service.impl;

import com.alibaba.fastjson.JSON;
import javax.annotation.Resource;
import cn.sciento.dd.dto.CreateChatDTO;
import cn.sciento.dd.dto.CreateChatResultDTO;
import cn.sciento.dd.dto.DefaultResultDTO;
import cn.sciento.dd.dto.GetChatResultDTO;
import cn.sciento.dd.dto.GetGroupMessageReadListResultDTO;
import cn.sciento.dd.dto.SendFileMessageDTO;
import cn.sciento.dd.dto.SendGroupFileMessageDTO;
import cn.sciento.dd.dto.SendGroupImageMessageDTO;
import cn.sciento.dd.dto.SendGroupIndependentCardMessageDTO;
import cn.sciento.dd.dto.SendGroupLinkMessageDTO;
import cn.sciento.dd.dto.SendGroupMarkDownMessageDTO;
import cn.sciento.dd.dto.SendGroupMessageResultDTO;
import cn.sciento.dd.dto.SendGroupOAMessageDTO;
import cn.sciento.dd.dto.SendGroupTextMessageDTO;
import cn.sciento.dd.dto.SendGroupVoiceMessageDTO;
import cn.sciento.dd.dto.SendGroupWholeCardMessageDTO;
import cn.sciento.dd.dto.SendImageMessageDTO;
import cn.sciento.dd.dto.SendIndependentCardMessageDTO;
import cn.sciento.dd.dto.SendLinkMessageDTO;
import cn.sciento.dd.dto.SendMarkDownMessageDTO;
import cn.sciento.dd.dto.SendMessageResultDTO;
import cn.sciento.dd.dto.SendOAMessageDTO;
import cn.sciento.dd.dto.SendTextMessageDTO;
import cn.sciento.dd.dto.SendVoiceMessageDTO;
import cn.sciento.dd.dto.SendWholeCardMessageDTO;
import cn.sciento.dd.dto.SendWorkFileMessageDTO;
import cn.sciento.dd.dto.SendWorkImageMessageDTO;
import cn.sciento.dd.dto.SendWorkIndependentCardMessageDTO;
import cn.sciento.dd.dto.SendWorkLinkMessageDTO;
import cn.sciento.dd.dto.SendWorkMarkDownMessageDTO;
import cn.sciento.dd.dto.SendWorkMessageResultDTO;
import cn.sciento.dd.dto.SendWorkOAMessageDTO;
import cn.sciento.dd.dto.SendWorkTextMessageDTO;
import cn.sciento.dd.dto.SendWorkVoiceMessageDTO;
import cn.sciento.dd.dto.SendWorkWholeCardMessageDTO;
import cn.sciento.dd.dto.UpdateChatDTO;
import cn.sciento.dd.dto.WorkMessageRecallDTO;
import cn.sciento.dd.dto.WorkProgressAndResultMessageDTO;
import cn.sciento.dd.dto.WorkProgressMessageResultDTO;
import cn.sciento.dd.dto.WorkResultMessageDTO;
import cn.sciento.dd.service.DingCorpMessageService;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

@Service
public class DingCorpMessageServiceImp implements DingCorpMessageService {
  @Resource(name = "wdRestTemplate")
  protected RestTemplate restTemplate;
  
  public SendWorkMessageResultDTO sendWorkTextMessage(String accessToken, SendWorkTextMessageDTO sendWorkTextMessageDTO) {
    return (SendWorkMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendWorkTextMessageDTO), (MultiValueMap)buildHttpHeaders()), SendWorkMessageResultDTO.class);
  }
  
  public SendWorkMessageResultDTO sendWorkImageMessage(String accessToken, SendWorkImageMessageDTO sendWorkImageMessageDTO) {
    return (SendWorkMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendWorkImageMessageDTO), (MultiValueMap)buildHttpHeaders()), SendWorkMessageResultDTO.class);
  }
  
  public SendWorkMessageResultDTO sendWorkVoiceMessage(String accessToken, SendWorkVoiceMessageDTO sendWorkVoiceMessageDTO) {
    return (SendWorkMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendWorkVoiceMessageDTO), (MultiValueMap)buildHttpHeaders()), SendWorkMessageResultDTO.class);
  }
  
  public SendWorkMessageResultDTO sendWorkFileMessage(String accessToken, SendWorkFileMessageDTO sendWorkFileMessageDTO) {
    return (SendWorkMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendWorkFileMessageDTO), (MultiValueMap)buildHttpHeaders()), SendWorkMessageResultDTO.class);
  }
  
  public SendWorkMessageResultDTO sendWorkLinkMessage(String accessToken, SendWorkLinkMessageDTO sendWorkLinkMessageDTO) {
    return (SendWorkMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token" + accessToken, new HttpEntity(JSON.toJSONString(sendWorkLinkMessageDTO), (MultiValueMap)buildHttpHeaders()), SendWorkMessageResultDTO.class);
  }
  
  public SendWorkMessageResultDTO sendWorkOAMessage(String accessToken, SendWorkOAMessageDTO sendWorkOAMessageDTO) {
    return (SendWorkMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendWorkOAMessageDTO), (MultiValueMap)buildHttpHeaders()), SendWorkMessageResultDTO.class);
  }
  
  public SendWorkMessageResultDTO sendWorkMarkDownMessage(String accessToken, SendWorkMarkDownMessageDTO sendWorkMarkDownMessageDTO) {
    return (SendWorkMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendWorkMarkDownMessageDTO), (MultiValueMap)buildHttpHeaders()), SendWorkMessageResultDTO.class);
  }
  
  public SendWorkMessageResultDTO sendWorkWholeCardMessage(String accessToken, SendWorkWholeCardMessageDTO sendWorkWholeCardMessageDTO) {
    return (SendWorkMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendWorkWholeCardMessageDTO), (MultiValueMap)buildHttpHeaders()), SendWorkMessageResultDTO.class);
  }
  
  public SendWorkMessageResultDTO sendWorkIndependentCardMessage(String accessToken, SendWorkIndependentCardMessageDTO sendWorkIndependentCardMessageDTO) {
    return (SendWorkMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?=" + accessToken, new HttpEntity(JSON.toJSONString(sendWorkIndependentCardMessageDTO), (MultiValueMap)buildHttpHeaders()), SendWorkMessageResultDTO.class);
  }
  
  public WorkProgressMessageResultDTO getWorkProgressMessage(String accessToken, WorkProgressAndResultMessageDTO workProgressAndResultMessageDTO) {
    return (WorkProgressMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/topapi/message/corpconversation/getsendprogress?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(workProgressAndResultMessageDTO), (MultiValueMap)buildHttpHeaders()), WorkProgressMessageResultDTO.class);
  }
  
  public WorkResultMessageDTO getWorkResultMessage(String accessToken, WorkProgressAndResultMessageDTO workProgressAndResultMessageDTO) {
    return (WorkResultMessageDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/topapi/message/corpconversation/getsendresult?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(workProgressAndResultMessageDTO), (MultiValueMap)buildHttpHeaders()), WorkResultMessageDTO.class);
  }
  
  public DefaultResultDTO getWorkMessageRecall(String accessToken, WorkMessageRecallDTO workMessageRecallDTO) {
    return (DefaultResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/topapi/message/corpconversation/recall?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(workMessageRecallDTO), (MultiValueMap)buildHttpHeaders()), WorkResultMessageDTO.class);
  }
  
  public SendGroupMessageResultDTO sendGroupTextMessage(String accessToken, SendGroupTextMessageDTO sendGroupTextMessageDTO) {
    return (SendGroupMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/chat/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendGroupTextMessageDTO), (MultiValueMap)buildHttpHeaders()), SendGroupMessageResultDTO.class);
  }
  
  public SendGroupMessageResultDTO sendGroupImageMessage(String accessToken, SendGroupImageMessageDTO sendGroupImageMessageDTO) {
    return (SendGroupMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/chat/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendGroupImageMessageDTO), (MultiValueMap)buildHttpHeaders()), SendGroupMessageResultDTO.class);
  }
  
  public SendGroupMessageResultDTO sendGroupVoiceMessage(String accessToken, SendGroupVoiceMessageDTO sendGroupVoiceMessageDTO) {
    return (SendGroupMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/chat/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendGroupVoiceMessageDTO), (MultiValueMap)buildHttpHeaders()), SendGroupMessageResultDTO.class);
  }
  
  public SendGroupMessageResultDTO sendGroupFileMessage(String accessToken, SendGroupFileMessageDTO sendGroupFileMessageDTO) {
    return (SendGroupMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/chat/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendGroupFileMessageDTO), (MultiValueMap)buildHttpHeaders()), SendGroupMessageResultDTO.class);
  }
  
  public SendGroupMessageResultDTO sendGroupLinkMessage(String accessToken, SendGroupLinkMessageDTO sendGroupLinkMessageDTO) {
    return (SendGroupMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/chat/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendGroupLinkMessageDTO), (MultiValueMap)buildHttpHeaders()), SendGroupMessageResultDTO.class);
  }
  
  public SendGroupMessageResultDTO sendGroupOAMessage(String accessToken, SendGroupOAMessageDTO sendGroupOAMessageDTO) {
    return (SendGroupMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/chat/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendGroupOAMessageDTO), (MultiValueMap)buildHttpHeaders()), SendGroupMessageResultDTO.class);
  }
  
  public SendGroupMessageResultDTO sendGroupMarkDownMessage(String accessToken, SendGroupMarkDownMessageDTO sendGroupMarkDownMessageDTO) {
    return (SendGroupMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/chat/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendGroupMarkDownMessageDTO), (MultiValueMap)buildHttpHeaders()), SendGroupMessageResultDTO.class);
  }
  
  public SendGroupMessageResultDTO sendGroupWholeCardMessage(String accessToken, SendGroupWholeCardMessageDTO sendGroupWholeCardMessageDTO) {
    return (SendGroupMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/chat/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendGroupWholeCardMessageDTO), (MultiValueMap)buildHttpHeaders()), SendGroupMessageResultDTO.class);
  }
  
  public SendGroupMessageResultDTO sendGroupIndependentCardMessage(String accessToken, SendGroupIndependentCardMessageDTO sendGroupIndependentCardMessageDTO) {
    return (SendGroupMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/chat/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendGroupIndependentCardMessageDTO), (MultiValueMap)buildHttpHeaders()), SendGroupMessageResultDTO.class);
  }
  
  public GetGroupMessageReadListResultDTO getGroupMessageReadList(String accessToken, String messageId, Long cursor, Integer size) {
    return (GetGroupMessageReadListResultDTO)this.restTemplate.getForObject("https://oapi.dingtalk.com/chat/getReadList?access_token=" + accessToken + "&messageId=" + messageId + "&cursor=" + cursor + "&size=" + size, GetGroupMessageReadListResultDTO.class);
  }
  
  public CreateChatResultDTO createChat(String accessToken, CreateChatDTO createChatDTO) {
    return (CreateChatResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/chat/create?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(createChatDTO), (MultiValueMap)buildHttpHeaders()), CreateChatResultDTO.class);
  }
  
  public DefaultResultDTO updateChat(String accessToken, UpdateChatDTO updateChatDTO) {
    return (DefaultResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/chat/update?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(updateChatDTO), (MultiValueMap)buildHttpHeaders()), DefaultResultDTO.class);
  }
  
  public GetChatResultDTO getChat(String accessToken, String chatid) {
    return (GetChatResultDTO)this.restTemplate.getForObject("https://oapi.dingtalk.com/chat/get?access_token=" + accessToken + "&chatid=" + chatid, GetChatResultDTO.class);
  }
  
  public SendMessageResultDTO sendTextMessage(String accessToken, SendTextMessageDTO sendTextMessageDTO) {
    return (SendMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/message/send_to_conversation?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendTextMessageDTO), (MultiValueMap)buildHttpHeaders()), SendMessageResultDTO.class);
  }
  
  public SendMessageResultDTO sendImageMessage(String accessToken, SendImageMessageDTO sendImageMessageDTO) {
    return (SendMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/message/send_to_conversation?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendImageMessageDTO), (MultiValueMap)buildHttpHeaders()), SendMessageResultDTO.class);
  }
  
  public SendMessageResultDTO sendVoiceMessage(String accessToken, SendVoiceMessageDTO sendVoiceMessageDTO) {
    return (SendMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/message/send_to_conversation?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendVoiceMessageDTO), (MultiValueMap)buildHttpHeaders()), SendMessageResultDTO.class);
  }
  
  public SendMessageResultDTO sendFileMessage(String accessToken, SendFileMessageDTO sendFileMessageDTO) {
    return (SendMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/message/send_to_conversation?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendFileMessageDTO), (MultiValueMap)buildHttpHeaders()), SendMessageResultDTO.class);
  }
  
  public SendMessageResultDTO sendLinkMessage(String accessToken, SendLinkMessageDTO sendLinkMessageDTO) {
    return (SendMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/message/send_to_conversation?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendLinkMessageDTO), (MultiValueMap)buildHttpHeaders()), SendMessageResultDTO.class);
  }
  
  public SendMessageResultDTO sendOAMessage(String accessToken, SendOAMessageDTO sendOAMessageDTO) {
    return (SendMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/message/send_to_conversation?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendOAMessageDTO), (MultiValueMap)buildHttpHeaders()), SendMessageResultDTO.class);
  }
  
  public SendMessageResultDTO sendMarkDownMessage(String accessToken, SendMarkDownMessageDTO sendMarkDownMessageDTO) {
    return (SendMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/message/send_to_conversation?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendMarkDownMessageDTO), (MultiValueMap)buildHttpHeaders()), SendMessageResultDTO.class);
  }
  
  public SendMessageResultDTO sendWholeCardMessage(String accessToken, SendWholeCardMessageDTO sendWholeCardMessageDTO) {
    return (SendMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/message/send_to_conversation?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendWholeCardMessageDTO), (MultiValueMap)buildHttpHeaders()), SendMessageResultDTO.class);
  }
  
  public SendMessageResultDTO sendIndependentCardMessage(String accessToken, SendIndependentCardMessageDTO sendIndependentCardMessageDTO) {
    return (SendMessageResultDTO)this.restTemplate.postForObject("https://oapi.dingtalk.com/message/send_to_conversation?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(sendIndependentCardMessageDTO), (MultiValueMap)buildHttpHeaders()), SendMessageResultDTO.class);
  }
  
  protected HttpHeaders buildHttpHeaders() {
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("Content-Type", "application/json");
    return httpHeaders;
  }
}
